using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using <Application>.Models;

namespace <Database>
{
    public class <OwnerU>_<TableU>Controller : Controller
    {
        private <Database>DBContext db = new <Database>DBContext();
        
        // GET: /<OwnerU>_<TableU>/
        public ActionResult Index()
        {
            return View(db.<OwnerU>_<TableU>.ToList());
        }

        // GET: /<OwnerU>_<TableU>/Details/<id>
        public ActionResult Details(
    <If Loop>
      <IsPKey>
      <And>
      <IsNullable>
      <And>
      <IsCurRow=[0]>
                                      <VBType>? <FieldU>
      <IsPKey>
      <And>
      <IsNullable>
      <And>
      <IsCurRow<>[0]>
                                     ,<VBType>? <FieldU>
      <IsPKey>
      <And>
      <IsNotNullable>
      <And>
      <IsCurRow=[0]>
                                      <VBType> <FieldU>
      <IsPKey>
      <And>
      <IsNotNullable>
      <And>
      <IsCurRow<>[0]>
                                     ,<VBType> <FieldU>
    </If Loop>
                                   )
    <If Loop>
      <IsPKey>
        {
            if (
        <ExitLoop>
    </If Loop>
    <If Loop>
      <IsPKey>
      <And>
      <IsCurRow=[0]>
                    <FieldU> == null
      <IsPKey>
      <And>
      <IsCurRow<>[0]>
                 || <FieldU> == null
    </If Loop>
               )
    <If Loop>
      <IsPKey>
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            <OwnerU>_<TableU> <OwnerU>_<TableU> = db.<OwnerU>_<TableU>.Find(
        <ExitLoop>
    </If Loop>
    <If Loop>
      <IsPKey>
      <And>
      <IsCurRow=[0]>
                                                 <FieldU>
      <IsPKey>
      <And>
      <IsCurRow<>[0]>
                                                ,<FieldU>
    </If Loop>
                                            );
    <If Loop>
      <IsPKey>
            if (<OwnerU>_<TableU> == null)
            {
                return HttpNotFound();
            }
            return View(<OwnerU>_<TableU>);
        }
        <ExitLoop>
    </If Loop>

        // GET: /<OwnerU>_<TableU>/Create
        public ActionResult Create()
        {
    <If Loop>
      <IsFKey>
        // ComboBox
      <ExitLoop>
    </If Loop>
    <If Loop>
    	<IsFKey>
            ViewBag.<RFieldU> = new SelectList(db.<ROwnerU>_<RTableU>, "<RFieldU>", "<RDisplayFieldU>");
    </If Loop>

            return View();
        }

        // POST: /<OwnerU>_<TableU>/Create
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
        // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create([Bind(Include=
		            <If Loop>
		               <IsNotIdentity>
				   <SF[+ "," + ]>"<Field>"
		            </If Loop>
				  )] <OwnerU>_<TableU> <OwnerU>_<TableU>)
        {
            if (ModelState.IsValid)
            {
                db.<OwnerU>_<TableU>.Add(<OwnerU>_<TableU>);
                db.SaveChanges();
                return RedirectToAction("Index");
            }
    <If Loop>
      <IsFKey>
        // ComboBox
      <ExitLoop>
    </If Loop>
    <If Loop>
    	<IsFKey>
            ViewBag.<RFieldU> = new SelectList(db.<ROwnerU>_<RTableU>, "<RFieldU>", "<RDisplayFieldU>", <OwnerU>_<TableU>.<FieldU>);
    </If Loop>

            return View(<OwnerU>_<TableU>);
        }

        // GET: /<OwnerU>_<TableU>/Edit/<id>
        public ActionResult Edit(
    <If Loop>
      <IsPKey>
      <And>
      <IsNullable>
      <And>
      <IsCurRow=[0]>
                                   <VBType>? <FieldU>
      <IsPKey>
      <And>
      <IsNullable>
      <And>
      <IsCurRow<>[0]>
                                  ,<VBType>? <FieldU>
      <IsPKey>
      <And>
      <IsNotNullable>
      <And>
      <IsCurRow=[0]>
                                   <VBType> <FieldU>
      <IsPKey>
      <And>
      <IsNotNullable>
      <And>
      <IsCurRow<>[0]>
                                  ,<VBType> <FieldU>
    </If Loop>
                                )
    <If Loop>
      <IsPKey>
        {
            if (
        <ExitLoop>
    </If Loop>
    <If Loop>
      <IsPKey>
      <And>
      <IsCurRow=[0]>
                    <FieldU> == null
      <IsPKey>
      <And>
      <IsCurRow<>[0]>
                 || <FieldU> == null
    </If Loop>
               )
    <If Loop>
      <IsPKey>
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            <OwnerU>_<TableU> <OwnerU>_<TableU> = db.<OwnerU>_<TableU>.Find(
        <ExitLoop>
    </If Loop>
    <If Loop>
      <IsPKey>
      <And>
      <IsCurRow=[0]>
                                                 <FieldU>
      <IsPKey>
      <And>
      <IsCurRow<>[0]>
                                                ,<FieldU>
    </If Loop>
                                            );
    <If Loop>
      <IsPKey>
            if (<OwnerU>_<TableU> == null)
            {
                return HttpNotFound();
            }
        <ExitLoop>
    </If Loop>
    <If Loop>
      <IsFKey>
        // ComboBox
      <ExitLoop>
    </If Loop>
    <If Loop>
    	<IsFKey>
            ViewBag.<RFieldU> = new SelectList(db.<ROwnerU>_<RTableU>, "<RFieldU>", "<RDisplayFieldU>", <OwnerU>_<TableU>.<FieldU>);
    </If Loop>

    <If Loop>
      <IsPKey>
            return View(<OwnerU>_<TableU>);
        }
        <ExitLoop>
    </If Loop>

        // POST: /<OwnerU>_<TableU>/Edit/<id>
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
        // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
        [HttpPost, ActionName("Edit")]
        [ValidateAntiForgeryToken]
        public ActionResult Edit(<OwnerU>_<TableU> <OwnerU>_<TableU>)
        {
            if (ModelState.IsValid)
            {
                db.Entry(<OwnerU>_<TableU>).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
    <If Loop>
      <IsFKey>
        // ComboBox
      <ExitLoop>
    </If Loop>
    <If Loop>
    	<IsFKey>
            ViewBag.<RFieldU> = new SelectList(db.<ROwnerU>_<RTableU>, "<RFieldU>", "<RDisplayFieldU>", <OwnerU>_<TableU>.<FieldU>);
    </If Loop>

            return View(<OwnerU>_<TableU>);
        }

        // GET: /<OwnerU>_<TableU>/Delete/<id>
        public ActionResult Delete(
    <If Loop>
      <IsPKey>
      <And>
      <IsNullable>
      <And>
      <IsCurRow=[0]>
                                     <VBType>? <FieldU>
      <IsPKey>
      <And>
      <IsNullable>
      <And>
      <IsCurRow<>[0]>
                                    ,<VBType>? <FieldU>
      <IsPKey>
      <And>
      <IsNotNullable>
      <And>
      <IsCurRow=[0]>
                                     <VBType> <FieldU>
      <IsPKey>
      <And>
      <IsNotNullable>
      <And>
      <IsCurRow<>[0]>
                                    ,<VBType> <FieldU>
    </If Loop>
                                  )
    <If Loop>
      <IsPKey>
        {
            if (
        <ExitLoop>
    </If Loop>
    <If Loop>
      <IsPKey>
      <And>
      <IsCurRow=[0]>
                    <FieldU> == null
      <IsPKey>
      <And>
      <IsCurRow<>[0]>
                 || <FieldU> == null
    </If Loop>
               )
    <If Loop>
      <IsPKey>
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            <OwnerU>_<TableU> <OwnerU>_<TableU> = db.<OwnerU>_<TableU>.Find(
        <ExitLoop>
    </If Loop>
    <If Loop>
      <IsPKey>
      <And>
      <IsCurRow=[0]>
                                                 <FieldU>
      <IsPKey>
      <And>
      <IsCurRow<>[0]>
                                                ,<FieldU>
    </If Loop>
                                            );
    <If Loop>
      <IsPKey>
            if (<OwnerU>_<TableU> == null)
            {
                return HttpNotFound();
            }
            return View(<OwnerU>_<TableU>);
        }
        <ExitLoop>
    </If Loop>

        // POST: /<OwnerU>_<TableU>/Delete/<id>
        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(
    <If Loop>
      <IsPKey>
      <And>
      <IsNullable>
      <And>
      <IsCurRow=[0]>
                                            <VBType>? <FieldU>
      <IsPKey>
      <And>
      <IsNullable>
      <And>
      <IsCurRow<>[0]>
                                            ,<VBType>? <FieldU>
      <IsPKey>
      <And>
      <IsNotNullable>
      <And>
      <IsCurRow=[0]>
                                            <VBType> <FieldU>
      <IsPKey>
      <And>
      <IsNotNullable>
      <And>
      <IsCurRow<>[0]>
                                            ,<VBType> <FieldU>
    </If Loop>
                                            )
    <If Loop>
      <IsPKey>
        {
            <OwnerU>_<TableU> <OwnerU>_<TableU> = db.<OwnerU>_<TableU>.Find(
        <ExitLoop>
    </If Loop>
    <If Loop>
      <IsPKey>
      <And>
      <IsCurRow=[0]>
                                                 <FieldU>
      <IsPKey>
      <And>
      <IsCurRow<>[0]>
                                                ,<FieldU>
    </If Loop>
                                            );
    <If Loop>
      <IsPKey>
            db.<OwnerU>_<TableU>.Remove(<OwnerU>_<TableU>);
            db.SaveChanges();
            return RedirectToAction("Index");
        }
        <ExitLoop>
    </If Loop>

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                db.Dispose();
            }
            base.Dispose(disposing);
        }
    }
}
